<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${classTypeNameMap[table.className+'Mapper']}">
  <resultMap id="BaseResultMap" type="${classTypeNameMap[table.className]}">
<#list table.columns as column>
  <#if column.pk == true>
    <id column="${column.columnName}" jdbcType="${column.columnTypeName}" property="${column.fieldNameFirstLower}" />
  <#else>
    <result column="${column.columnName}" jdbcType="${column.columnTypeName}" property="${column.fieldNameFirstLower}" />
  </#if>
</#list>
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and <#noparse>$</#noparse>{criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and <#noparse>$</#noparse>{criterion.condition} <#noparse>#</#noparse>{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and <#noparse>$</#noparse>{criterion.condition} <#noparse>#</#noparse>{criterion.value} and <#noparse>#</#noparse>{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and <#noparse>$</#noparse>{criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    <#noparse>#</#noparse>{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and <#noparse>$</#noparse>{criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and <#noparse>$</#noparse>{criterion.condition} <#noparse>#</#noparse>{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and <#noparse>$</#noparse>{criterion.condition} <#noparse>#</#noparse>{criterion.value} and <#noparse>#</#noparse>{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and <#noparse>$</#noparse>{criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    <#noparse>#</#noparse>{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <#list table.columns as column>${column.columnName}<#if column_has_next>, </#if><#if column_has_next && ((column_index+1)%8 == 0)>${"\n"}    </#if></#list>
  </sql>
  <sql id="VO_COLUMN_LIST">
    <#list table.columns as column>${column.columnName} AS ${column.fieldNameFirstLower}<#if column_has_next>, </#if><#if column_has_next && ((column_index+1)%8 == 0)>${"\n"}    </#if></#list>
  </sql>
  <sql id="VO_CONDITION">
    <where>
    <#list table.columns as column>
    <#if column.fieldType == "String">
      <if test='${column.fieldNameFirstLower} != null and ${column.fieldNameFirstLower} !=""'>AND ${column.columnName} = <#noparse>#</#noparse>{${column.fieldNameFirstLower}}</if>
    <#else>
      <if test='${column.fieldNameFirstLower} != null'>AND ${column.columnName} = <#noparse>#</#noparse>{${column.fieldNameFirstLower}}</if>
    </#if>
    </#list>
      <if test="idNotEqualTo != null">AND id != <#noparse>#</#noparse>{idNotEqualTo}</if>
    </where>
  </sql>
  <select id="selectByExample" parameterType="${classTypeNameMap[table.className+'Example']}" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from ${table.tableName}
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by <#noparse>$</#noparse>{orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from ${table.tableName}
    where <#list table.pkColumns as column>${column.columnName} = <#noparse>#</#noparse>{${column.fieldNameFirstLower},jdbcType=${column.columnTypeName}}<#if column_has_next> and </#if></#list>
  </select>
  <select id="selectList" resultType="${classTypeNameMap[table.className+'VO']}" parameterType="${classTypeNameMap[table.className+'VO']}">
    SELECT
    <include refid="VO_COLUMN_LIST"/>
    FROM ${table.tableName}
    <include refid="VO_CONDITION"/>
    ORDER BY id DESC
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from ${table.tableName}
    where <#list table.pkColumns as column>${column.columnName} = <#noparse>#</#noparse>{${column.fieldNameFirstLower},jdbcType=${column.columnTypeName}}<#if column_has_next> and </#if></#list>
  </delete>
  <delete id="deleteByExample" parameterType="${classTypeNameMap[table.className+'Example']}">
    delete from ${table.tableName}
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="${classTypeNameMap[table.className]}" useGeneratedKeys="true" keyProperty="id">
    insert into ${table.tableName} (<#list table.columns as column>${column.columnName}<#if column_has_next>, </#if><#if column_has_next && ((column_index+1)%3 == 0)>${"\n"}      </#if></#list>
    )values( <#list table.columns as column><#noparse>#</#noparse>{${column.fieldNameFirstLower},jdbcType=${column.columnTypeName}}<#if column_has_next>, </#if><#if column_has_next && ((column_index+1)%3 == 0)>${"\n"}      </#if></#list>
    )
  </insert>
  <insert id="insertSelective" parameterType="${classTypeNameMap[table.className]}" useGeneratedKeys="true" keyProperty="id">
    insert into ${table.tableName}
    <trim prefix="(" suffix=")" suffixOverrides=",">
    <#list table.columns as column>
      <if test="${column.fieldNameFirstLower} != null">${column.columnName},</if>
    </#list>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
    <#list table.columns as column>
      <if test="${column.fieldNameFirstLower} != null"><#noparse>#</#noparse>{${column.fieldNameFirstLower},jdbcType=${column.columnTypeName}},</if>
    </#list>
    </trim>
  </insert>
  <insert id="insertBatch" parameterType="java.util.List">
    insert into ${table.tableName} (<#list table.columns as column>${column.columnName}<#if column_has_next>,</#if><#if column_has_next && ((column_index+1)%3 == 0)>${"\n"}      </#if></#list>
    )values
    <foreach collection="list" item="item" separator=",">
      (<#list table.columns as column><#noparse>#</#noparse>{item.${column.fieldNameFirstLower}}<#if column_has_next>,</#if><#if column_has_next && ((column_index+1)%3 == 0)>${"\n"}      </#if></#list>)
    </foreach>
  </insert>
  <select id="countByExample" parameterType="${classTypeNameMap[table.className+'Example']}" resultType="java.lang.Long">
    select count(*) from ${table.tableName}
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update ${table.tableName}
    <set>
    <#list table.columns as column>
      <if test="entity.${column.fieldNameFirstLower} != null"> ${column.columnName} = <#noparse>#</#noparse>{entity.${column.fieldNameFirstLower},jdbcType=${column.columnTypeName}},</if>
    </#list>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update ${table.tableName}
    set
    <#list table.columns as column>
    ${column.columnName} = <#noparse>#</#noparse>{entity.${column.fieldNameFirstLower},jdbcType=${column.columnTypeName}}<#if column_has_next>,</#if>
    </#list>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="${classTypeNameMap[table.className]}">
    update ${table.tableName}
    <set>
    <#list table.columns as column>
      <if test="${column.fieldNameFirstLower} != null"> ${column.columnName} = <#noparse>#</#noparse>{${column.fieldNameFirstLower},jdbcType=${column.columnTypeName}},</if>
    </#list>
    </set>
    where <#list table.pkColumns as column>${column.columnName} = <#noparse>#</#noparse>{${column.fieldNameFirstLower},jdbcType=${column.columnTypeName}}<#if column_has_next> and </#if></#list>
  </update>
  <update id="updateByPrimaryKey" parameterType="${classTypeNameMap[table.className]}">
    update ${table.tableName}
    set
    <#list table.columns as column>
      ${column.columnName} = <#noparse>#</#noparse>{${column.fieldNameFirstLower},jdbcType=${column.columnTypeName}}<#if column_has_next>,</#if>
    </#list>
    where <#list table.pkColumns as column>${column.columnName} = <#noparse>#</#noparse>{${column.fieldNameFirstLower},jdbcType=${column.columnTypeName}}<#if column_has_next> and </#if></#list>
  </update>
</mapper>